package com.tongguan.paypos.base;

import android.app.Application;
import android.os.Build;

import com.basewin.log.LogUtil;
import com.basewin.services.ServiceManager;
import com.tencent.bugly.crashreport.CrashReport;
import com.tongguan.paypos.BuildConfig;
import com.tongguan.paypos.entity.PayType;
import com.tongguan.paypos.utils.L;
import com.uuzuche.lib_zxing.activity.ZXingLibrary;
import com.zhy.http.okhttp.OkHttpUtils;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

public class MyApplication extends Application {

    private static MyApplication app;
    private ArrayList<PayType> payTypes;

    public ArrayList<PayType> getPayTypes() {
        return payTypes;
    }

    public void setPayTypes(ArrayList<PayType> payTypes) {
        this.payTypes = payTypes;
    }

    public static MyApplication getInstance() {
        if (app == null) {
            app = new MyApplication();
        }
        return app;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        //初始化 L 打印  设置 tag  在 release 下设置false
        L.init(BuildConfig.isLog, "log");
        //初始化 网络请求 超时时间 log 在 release 下 注释关闭掉
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
//                 .addInterceptor(new LoggerInterceptor("myhttp"))
                .connectTimeout(30000L, TimeUnit.MILLISECONDS)
                .readTimeout(15000L, TimeUnit.MILLISECONDS)
                //其他配置
                .build();
        OkHttpUtils.initClient(okHttpClient);
        L.d("欢迎使用东莞金服");
        ZXingLibrary.initDisplayOpinion(getApplicationContext());
        //初始化Bugly  收集
//        CrashReport.initCrashReport(getApplicationContext(), "7dabefd517", BuildConfig.isLog);
        if (Build.MANUFACTURER.contains("basewin")) {
            // init service manager
            ServiceManager.getInstence().init(getApplicationContext());
             if (!BuildConfig.isLog){
                 //关闭log
                 LogUtil.closeLog();
             }
        }

    }
}
